#ifndef WAVEIO_H_INCLUDE
#define WAVEIO_H_INCLUDE

#include <stdio.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define WAVFILE_SAMPLE_RATE     (48000)
#define WAVFILE_BIT_PER_SAMPLE  (16)
#define FRAME_LENGTH 1024
#define HOP_SIZE 512
#define PAI 3.141592653589793
const int max_int16_t=32768;

typedef struct {
    char    riff_tag[4];
    int     riff_length;
    char    format[4];
    char    fmt_tag[4];
    int     fmt_length;
    short   fmt_audio_code;
    short   fmt_channel_num;
    int     fmt_sample_rate;
    int     fmt_byte_rate;
    short   fmt_block_align;
    short   fmt_bit_per_sample;
    char    data_tag[4];
    int     data_length;
} waveHeader_t;

/* open read file and get the wav header */
FILE *wavfile_read_open(const char *filename, waveHeader_t *header);

/* read audio data from file */
//int wavfile_read(FILE *fp, const char *data, size_t size);
int wavfile_read(FILE *fp, const int16_t *data, size_t size);
/* close read file */
void wavfile_read_close(FILE *fp);

int wavfile_rewind(FILE *fp);

/* open write file with channels */
FILE *wavfile_write_open(const char *filename, int channels, int sample_rate);

/* write audio data to file */
//int wavfile_write(FILE *fp, const char *data, size_t size);
int wavfile_write(FILE *fp, const int16_t *data, size_t size);
/* close write file */
void wavfile_write_close(FILE *fp);

#ifdef __cplusplus
}
#endif


#endif